using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VITDTRACE
    {
        public DataRow Convert2ITDTRACE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryITDTRACE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ITDSA"] = " ".PadRight(2 ); 
         dwReturn["ITDPROG"] = " ".PadRight(8 ); 
         dwReturn["ITDKENNZ"] = " ".PadRight(1 ); 
         dwReturn["ITDDATUM"] = " ".PadRight(0 ); 
         dwReturn["ITDZEIT"] = " ".PadRight(0 ); 
         dwReturn["ITDOPTR"] = " ".PadRight(0 ); 
         dwReturn["ITDSETL"] = " ".PadRight(0 ); 
         dwReturn["ITDRNXT"] = " ".PadRight(0 ); 
         dwReturn["ITDRDIR"] = " ".PadRight(0 ); 
         dwReturn["ITDRNHD"] = " ".PadRight(0 ); 
         dwReturn["ITDRHLD"] = " ".PadRight(0 ); 
         dwReturn["ITDINSR"] = " ".PadRight(0 ); 
         dwReturn["ITDDLET"] = " ".PadRight(0 ); 
         dwReturn["ITDREWR"] = " ".PadRight(0 ); 
         dwReturn["ITDCLTR"] = " ".PadRight(0 ); 
         dwReturn["ITDRSTR"] = " ".PadRight(0 ); 
         dwReturn["ITDLOCK"] = " ".PadRight(0 ); 
         dwReturn["ITDLOCKANZ"] = " ".PadRight(0 ); 
         dwReturn["ITDLOCKFEHL"] = " ".PadRight(0 ); 
         dwReturn["ITDHSEKUNDEN"] = " ".PadRight(0 ); 
         dwReturn["ITDSUMME"] = " ".PadRight(0 ); 
         dwReturn["ITDSCHNITT"] = " ".PadRight(0 ); 
         dwReturn["ITDUSER"] = " ".PadRight(8 ); 
         dwReturn["ITDFILLER"] = " ".PadRight(7 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapITDTRACE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveITDTRACE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryITDTRACE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapITDTRACE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertITDTRACE(dwLocal, ITXDBVERSION);
            }
            UpdateITDTRACE(dwLocal);
        }
        public void InsertITDTRACE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ITDTRACE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryITDTRACE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ITDTRACE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ITDTRACE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ITDTRACE";
            Return = Result;
            return Return;
        }
        public void DeleteITDTRACE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ITDTRACE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateITDTRACE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ITDTRACE SET "
                    +"ITDSA= :ITDSA,"
                    +"ITDPROG= :ITDPROG,"
                    +"ITDKENNZ= :ITDKENNZ,"
                    +"ITDDATUM= :ITDDATUM,"
                    +"ITDZEIT= :ITDZEIT,"
                    +"ITDOPTR= :ITDOPTR,"
                    +"ITDSETL= :ITDSETL,"
                    +"ITDRNXT= :ITDRNXT,"
                    +"ITDRDIR= :ITDRDIR,"
                    +"ITDRNHD= :ITDRNHD,"
                    +"ITDRHLD= :ITDRHLD,"
                    +"ITDINSR= :ITDINSR,"
                    +"ITDDLET= :ITDDLET,"
                    +"ITDREWR= :ITDREWR,"
                    +"ITDCLTR= :ITDCLTR,"
                    +"ITDRSTR= :ITDRSTR,"
                    +"ITDLOCK= :ITDLOCK,"
                    +"ITDLOCKANZ= :ITDLOCKANZ,"
                    +"ITDLOCKFEHL= :ITDLOCKFEHL,"
                    +"ITDHSEKUNDEN= :ITDHSEKUNDEN,"
                    +"ITDSUMME= :ITDSUMME,"
                    +"ITDSCHNITT= :ITDSCHNITT,"
                    +"ITDUSER= :ITDUSER,"
                    +"ITDFILLER= :ITDFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ITDSA", OracleType.NVarChar).Value = dwData["ITDSA"].ToString(); 
          or1.Parameters.Add("ITDPROG", OracleType.NVarChar).Value = dwData["ITDPROG"].ToString(); 
          or1.Parameters.Add("ITDKENNZ", OracleType.NVarChar).Value = dwData["ITDKENNZ"].ToString(); 
          or1.Parameters.Add("ITDDATUM", OracleType.NVarChar).Value = dwData["ITDDATUM"].ToString(); 
          or1.Parameters.Add("ITDZEIT", OracleType.NVarChar).Value = dwData["ITDZEIT"].ToString(); 
          or1.Parameters.Add("ITDOPTR", OracleType.NVarChar).Value = dwData["ITDOPTR"].ToString(); 
          or1.Parameters.Add("ITDSETL", OracleType.NVarChar).Value = dwData["ITDSETL"].ToString(); 
          or1.Parameters.Add("ITDRNXT", OracleType.NVarChar).Value = dwData["ITDRNXT"].ToString(); 
          or1.Parameters.Add("ITDRDIR", OracleType.NVarChar).Value = dwData["ITDRDIR"].ToString(); 
          or1.Parameters.Add("ITDRNHD", OracleType.NVarChar).Value = dwData["ITDRNHD"].ToString(); 
          or1.Parameters.Add("ITDRHLD", OracleType.NVarChar).Value = dwData["ITDRHLD"].ToString(); 
          or1.Parameters.Add("ITDINSR", OracleType.NVarChar).Value = dwData["ITDINSR"].ToString(); 
          or1.Parameters.Add("ITDDLET", OracleType.NVarChar).Value = dwData["ITDDLET"].ToString(); 
          or1.Parameters.Add("ITDREWR", OracleType.NVarChar).Value = dwData["ITDREWR"].ToString(); 
          or1.Parameters.Add("ITDCLTR", OracleType.NVarChar).Value = dwData["ITDCLTR"].ToString(); 
          or1.Parameters.Add("ITDRSTR", OracleType.NVarChar).Value = dwData["ITDRSTR"].ToString(); 
          or1.Parameters.Add("ITDLOCK", OracleType.NVarChar).Value = dwData["ITDLOCK"].ToString(); 
          or1.Parameters.Add("ITDLOCKANZ", OracleType.NVarChar).Value = dwData["ITDLOCKANZ"].ToString(); 
          or1.Parameters.Add("ITDLOCKFEHL", OracleType.NVarChar).Value = dwData["ITDLOCKFEHL"].ToString(); 
          or1.Parameters.Add("ITDHSEKUNDEN", OracleType.NVarChar).Value = dwData["ITDHSEKUNDEN"].ToString(); 
          or1.Parameters.Add("ITDSUMME", OracleType.NVarChar).Value = dwData["ITDSUMME"].ToString(); 
          or1.Parameters.Add("ITDSCHNITT", OracleType.NVarChar).Value = dwData["ITDSCHNITT"].ToString(); 
          or1.Parameters.Add("ITDUSER", OracleType.NVarChar).Value = dwData["ITDUSER"].ToString(); 
          or1.Parameters.Add("ITDFILLER", OracleType.NVarChar).Value = dwData["ITDFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
